<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddStationLettersTable extends Migration {

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
        Schema::create('station_letters', function(Blueprint $table)
        {
            $table->increments('id');
            $table->integer('to');
            $table->string('subject');
            $table->text('message');
            $table->integer('creator_id');
            $table->tinyInteger('is_read');

            $table->timestamps();
            $table->softDeletes();

            $table->index(array('to', 'creator_id', 'created_at'));
            $table->index(array('to', 'is_read'));
        });

        Schema::create('station_letter_users', function(Blueprint $table)
        {
            $table->increments('id');
            $table->integer('to');
            $table->integer('user_id');
            $table->tinyInteger('unread_count')->default(0);;
            $table->tinyInteger('total_count')->default(0);;

            $table->timestamps();
            $table->softDeletes();

            $table->unique(array('to', 'user_id'));
            $table->index(array('to', 'updated_at'));
        });
	}

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
        Schema::dropIfExists('station_letters');
        Schema::dropIfExists('station_letter_users');
	}

}
